//
//  TimelineUnitCell.m
//  Growth
//
//  Created by Hobo.Chen on 6/1/12.
//  Copyright (c) 2012 MEETStudio. All rights reserved.
//

#import "TimelineUnitCell.h"

@implementation TimelineUnitCell

@synthesize imageView1;
@synthesize imageView2;
@synthesize imageView3;

@synthesize iconButton;

@synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)dealloc{
    
    CLog(@"dealloc");
    
    [imageView1 release];
    [imageView2 release];
    [imageView3 release];
    
    [iconButton release];
    [iconImageView release];
    
    [dayLabel release];
    [monthLabel release];
    [hourLable release];
    [adressLabel release];
    
    [conttentView release];
    
    [nameLabel release];
    [likeNumLabel release];
    [commentNumLabel release];
    
    
    [fullScreenButton1 release];
    [fullScreenButton2 release];
    [fullScreenButton3 release];
    
    [conttentLabel release];
    
    [visitView release];
    
    [super dealloc];
}


- (void)viewDidLoad
{
    
    iconImageView.layer.cornerRadius = 3;
    iconImageView.clipsToBounds = YES;
    
    [dayLabel setTextColor:Text_Color];
    [monthLabel setTextColor:Text_Color];
    [adressLabel setTextColor:Text_Color];
    
    [nameLabel setTextColor:Text_Color];
    [likeNumLabel setTextColor:Text_Color];
    [commentNumLabel setTextColor:Text_Color];
    
    conttentView.layer.shadowColor = [[UIColor darkGrayColor] CGColor];
    conttentView.layer.shadowOffset = CGSizeMake(0.5, 0.5);
    conttentView.layer.shadowOpacity = 0.5;
    
    conttentView.layer.cornerRadius = 3;
    
        
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)conttentViewShadow
{
    conttentView.layer.cornerRadius = 3;
    
    conttentView.layer.shadowOpacity = 0.4;
	conttentView.layer.shadowRadius = 1.5;
	conttentView.layer.shadowOffset = CGSizeMake(0, 0);
    CGRect shadowFrame = conttentView.layer.bounds;
    CLog(@"shadow frame rect %f, %f, %f, %f", shadowFrame.origin.x, shadowFrame.origin.y, shadowFrame.size.width, shadowFrame.size.height);
    CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(shadowFrame.origin.x, shadowFrame.origin.y, shadowFrame.size.width, shadowFrame.size.height +2)].CGPath;
    conttentView.layer.shadowPath = shadowPath;
}

- (void)loadCellViewWith:(NSDictionary *)dict{
    
    if (dict == nil) {
        
        return;
           
    }
    
    if ([[dict objectForKey:@"ThreadID"] isMemberOfClass:[NSNull class]]) {
        
        //cell  height
        CGRect cellFrame = [self frame];
        cellFrame.origin = CGPointMake(0, 0);
        
        cellFrame.size.height = 0;
        [self setFrame:cellFrame];
        
        return;
    }
    
    conttentView.hidden = NO;
    
    iconImageView.layer.cornerRadius = 3;
    iconImageView.clipsToBounds = YES;
    
    [dayLabel setTextColor:[UIColor darkGrayColor]];
    [monthLabel setTextColor:[UIColor darkGrayColor]];
    [adressLabel setTextColor:[UIColor darkGrayColor]];
    
    [nameLabel setTextColor:Text_Color];
    [likeNumLabel setTextColor:Text_Color];
    [commentNumLabel setTextColor:Text_Color];
    
      //发表时间
    
    long long int creatTime ;
    
    if (![[dict objectForKey:@"DateCreated"] isMemberOfClass:[NSNull class]]) {
        
        NSDate *zoneDate = [NSDate date];
        NSTimeZone *zone = [NSTimeZone defaultTimeZone];//获得当前应用程序默认的时区
        NSInteger interval = [zone secondsFromGMTForDate:zoneDate];//以秒为单位返回当前应用程序与世界标准时间（格林威尼时间）的时差
        NSString *DateCreated = [dict objectForKey:@"DateCreated"];
        NSString *dateStr = [DateCreated substringWithRange:NSMakeRange(6, 13)];
        
        creatTime = [dateStr longLongValue];
        creatTime = creatTime/1000 +interval;
        
        //日志时间
        NSDate *nd = [NSDate dateWithTimeIntervalSince1970:creatTime];

        CLog(@"create date %@", nd);

        NSString *createDateStr = [[PublicMethodEngine sharedPublicMethodEngine] NSDateToNSTring:nd];
        int create_year = [[createDateStr substringWithRange: NSMakeRange(0, 4)] intValue];
        int create_month=[[createDateStr substringWithRange: NSMakeRange(5, 2)] intValue];
        int create_day=[[createDateStr substringWithRange: NSMakeRange(8, 2)] intValue];

        NSString *hour = [createDateStr substringFromIndex:10];
        hourLable.text = hour;
        
        
        CLog(@"create %d:%d:%d",create_year, create_month, create_day);
        
        NSString *dayString;
        
        if (create_day < 10) {
            dayString = [NSString stringWithFormat:@"0%d",create_day];
            
        }
        else{
            
            dayString = [NSString stringWithFormat:@"%d",create_day];
            
        }
        
        
        NSString *monthString = [NSString stringWithFormat:@"%d月",create_month];
        
        dayLabel.text = dayString;
        monthLabel.text = monthString;
        
        
        //当前时间
        NSDate *date=[NSDate dateWithTimeIntervalSinceNow:interval];
        
        NSString *curDateStr = [[PublicMethodEngine sharedPublicMethodEngine] NSDateToNSTring:date];
        int cur_year = [[curDateStr substringWithRange: NSMakeRange(0, 4)] intValue];
        int cur_month=[[curDateStr substringWithRange: NSMakeRange(5, 2)] intValue];
        int cur_day=[[curDateStr substringWithRange: NSMakeRange(8, 2)] intValue];
        
        CLog(@"current %d:%d:%d",cur_year, cur_month, cur_day);
        
        if (cur_year == create_year && cur_month == create_month && cur_day == create_day) {
            dayString = @"今天";
            monthString = @"";
            dayLabel.text=dayString;
            monthLabel.text = monthString;
            [dayLabel setFrame:CGRectMake(7, 50, 50, 26)];
            
        }
        if (cur_year == create_year && cur_month == create_month && cur_day == create_day+1) {
            dayString = @"昨天";
            monthString = @"";
            dayLabel.text=dayString;
            [dayLabel setFrame:CGRectMake(7, 50, 50, 26)];
            monthLabel.text = monthString;
        }
        
    }
    
    likeNumLabel.text = [NSString stringWithFormat:@" %@",[dict objectForKey:@"ReplyCount"] ];
    commentNumLabel.text = [NSString stringWithFormat:@" %@",[dict objectForKey:@"ReplyCount"] ];
       
           
        conttentLabel.numberOfLines = 0;
        conttentLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        conttentLabel.backgroundColor = [UIColor clearColor];
        [conttentLabel setFont:[UIFont systemFontOfSize:14]];
        
        
        NSString *content = [dict objectForKey:@"Body"];
        content = [self changeStringFommat:content];
        
              
        UIFont *font = [UIFont systemFontOfSize:15];
        CGSize size = CGSizeMake(245,2000);
        CGSize labelsize = [content sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeCharacterWrap];                
        
        [conttentLabel setFrame:CGRectMake(6, 25, labelsize.width, labelsize.height+10)];
        conttentLabel.text = content;
        conttentLabel.backgroundColor = [UIColor clearColor];
    
       //转发内容
    if (![[dict objectForKey:@"GetOriginalThread"] isMemberOfClass:[NSNull class]]) {
        
        NSDictionary *subDict = [dict objectForKey:@"GetOriginalThread"];
        NSString *subContent = [NSString stringWithFormat:@"%@: %@",[subDict objectForKey:@"Author"],[subDict objectForKey:@"Body"]];
        UIFont *font = [UIFont systemFontOfSize:15];
        CGSize size = CGSizeMake(235,2000);
        CGSize labelsize = [subContent sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeCharacterWrap];
               
        UILabel *subContentLable = [[UILabel alloc]initWithFrame:CGRectMake(conttentLabel.frame.origin.x + 7, conttentLabel.frame.origin.y + conttentLabel.frame.size.height, labelsize.width, labelsize.height +5)];
        
        subContentLable.numberOfLines = 0;
        subContentLable.lineBreakMode = UILineBreakModeCharacterWrap;
        subContentLable.textColor = [UIColor darkGrayColor];
        [subContentLable setFont:[UIFont systemFontOfSize:14]];
        
        //bg
        UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(subContentLable.frame.origin.x-5, subContentLable.frame.origin.y, 235, labelsize.height +25)];
        bgImageView.image = [[UIImage imageNamed:@"bian2_geren_iphone.png"] stretchableImageWithLeftCapWidth:100 topCapHeight:30];
        [conttentView addSubview:bgImageView];
                
        //time
        NSDate *zoneDate = [NSDate date];
        NSTimeZone *zone = [NSTimeZone defaultTimeZone];//获得当前应用程序默认的时区
        NSInteger interval = [zone secondsFromGMTForDate:zoneDate];//以秒为单位返回当前应用程序与世界标准时间（格林威尼时间）的时差
        NSString *DateCreated = [subDict objectForKey:@"DateCreated"];
        NSString *dateStr = [DateCreated substringWithRange:NSMakeRange(6, 13)];
        
        creatTime = [dateStr longLongValue];
        creatTime = creatTime/1000 +interval;
        
        //日志时间
        NSDate *nd = [NSDate dateWithTimeIntervalSince1970:creatTime];
        
        CLog(@"create date %@", nd);
        
        NSString *createDateStr = [[PublicMethodEngine sharedPublicMethodEngine] NSDateToNSTring:nd];
        UILabel *subTimeLable = [[UILabel alloc]initWithFrame:CGRectMake(115, bgImageView.frame.size.height -25, 140, 25)];
        subTimeLable.textColor = [UIColor darkGrayColor];
        subTimeLable.font = [UIFont systemFontOfSize:12];
        subTimeLable.backgroundColor = [UIColor clearColor];
        subTimeLable.text = createDateStr;
        [bgImageView addSubview:subTimeLable];
        [subTimeLable release];
        
        
        [bgImageView release];
        
        [conttentView addSubview:subContentLable];
        subContentLable.backgroundColor = [UIColor clearColor];
        subContentLable.text = subContent;
        
        
        
        [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, conttentLabel.frame.size.height +60 + labelsize.height+5)];
        [self conttentViewShadow];

        
    }
    else{
        
        
        
        [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, conttentLabel.frame.size.height +40)];
        [self conttentViewShadow];

    }
        
        
    if (conttentView.frame.size.height <80) {
            [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, 80)];
            [self conttentViewShadow];
            
           }
    
    
    conttentView.hidden = NO;
    
    CGRect cellFrame = [self frame];
    cellFrame.origin = CGPointMake(0, 0);
    
    cellFrame.size.height = conttentView.frame.size.height + 20;
    [self setFrame:cellFrame];
    
    
}


- (void)initTimelineIconButton:(NSDictionary *)dict{
    
    
    //好友名字
    if(![[dict objectForKey:@"userNickname"] isMemberOfClass:[NSNull class]]){
        
        NSString *friendName=[dict objectForKey:@"userNickname"]; 
        
        nameLabel.text = friendName;
        
	}
    
    
	//好友头像
    if(![[dict objectForKey:@"userAttachmentId"] isMemberOfClass:[NSNull class]]){
        
        
        NSString *string=[NSString stringWithFormat:@"%@/%@/%@/100x100",UCENTERBASEURL,@"gravatar",[dict objectForKey:@"userAttachmentId"]];
        NSURL *url = [NSURL URLWithString:string];	
        CLog(@"icon url %@", string);
        
        //[iconImageView setImageWithURL:url imageType:kImageCache_Content_Icon]; 
        //[self setImageViewWith:iconImageView url:url imageType:kImageCache_Content_Icon];
        [iconImageView setImageWithURL:url refreshCache:NO placeholderImage:[UIImage imageNamed:@"geren_set_iphone.png"] imageType:kImageCache_Content_Icon];
        
        
        
        if(![[dict objectForKey:@"userId"] isMemberOfClass:[NSNull class]]){
            iconButton.tag = [[dict objectForKey:@"userId"] intValue];
            [iconButton addTarget:self action:@selector(toUserView:) forControlEvents:UIControlEventTouchUpInside];   
        }
        
	}
    
    
    
}

- (void)initNewsIconButton:(NSDictionary *)dict{
    
    
    //好友名字
    if(![[dict objectForKey:@"Author"] isMemberOfClass:[NSNull class]]){
        
        NSString *friendName=[dict objectForKey:@"Author"]; 
        
        nameLabel.text = friendName;
        
	}
    
    
	//宝宝头像
//    if(![[dict objectForKey:@"ThumbnailUrl"] isMemberOfClass:[NSNull class]]){
//        
//        
//        NSString *string=[NSString stringWithFormat:@"%@%@/%@/100x100",BASEURL,@"/commons/attachment/download",[dict objectForKey:@"timelineAttachmentId"]];
//        NSURL *url = [NSURL URLWithString:string];	
//        CLog(@"icon url %@", string);
//        
//        iconImageView.layer.cornerRadius = 25;
//        iconImageView.clipsToBounds = YES;
//        
//        
//        [iconImageView setImageWithURL:url refreshCache:NO placeholderImage:[UIImage imageNamed:@"nophoto_bb_iphone.png"] imageType:kImageCache_Content_Icon];
//        
//        if(![[dict objectForKey:@"timelineId"] isMemberOfClass:[NSNull class]]){
//            iconButton.tag = [[dict objectForKey:@"timelineId"] intValue];
//            [iconButton addTarget:self action:@selector(toBabyTimelineView:) forControlEvents:UIControlEventTouchUpInside];     
//        }
//        
//	}
    
    
    
}

- (void)setImageViewWith:(UIImageView *)imageView url:(NSURL *)url imageType:(NSString *)imageType
{
    if (imageView.image == nil) {
        [imageView setImageWithURL:url imageType:imageType];
       
    }
}



#pragma mark 本地记录的显示
- (void)loadcellViewWithLocal:(NSDictionary *)dict{
    
    if (dict == nil) {
        
        return;
        
        
    }
    
    NSDictionary *diaryDict;
    
    NSString *JsonString = [dict objectForKey:@"json"];
    if (JsonString != nil) {
        NSError *error = nil;
        NSData *dat=[JsonString dataUsingEncoding: NSUTF8StringEncoding];
        diaryDict = [[CJSONDeserializer deserializer] deserializeAsDictionary:dat error:&error];
    }
    else{
        
        CGRect cellFrame = [self frame];
        cellFrame.origin = CGPointMake(0, 0);
        
        cellFrame.size.height = 0;
        [self setFrame:cellFrame];
        
        return;
        
        
        
    }
    
    conttentView.hidden = NO;
    
    iconImageView.layer.cornerRadius = 3;
    iconImageView.clipsToBounds = YES;
    
    [dayLabel setTextColor:[UIColor darkGrayColor]];
    [monthLabel setTextColor:[UIColor darkGrayColor]];
    [adressLabel setTextColor:[UIColor darkGrayColor]];
    
    [nameLabel setTextColor:Text_Color];
    [likeNumLabel setTextColor:Text_Color];
    [commentNumLabel setTextColor:Text_Color];
    
    
    //发表时间
    
    long long int creatTime ;
    
    if ([diaryDict.allKeys containsObject:@"createdDate"]){
        NSDate *zoneDate = [NSDate date];
        NSTimeZone *zone = [NSTimeZone defaultTimeZone];//获得当前应用程序默认的时区
        NSInteger interval = [zone secondsFromGMTForDate:zoneDate];//以秒为单位返回当前应用程序与世界标准时间（格林威尼时间）的时差
        
        creatTime = [[diaryDict objectForKey:@"createdDate"] longLongValue];
        creatTime = creatTime/1000 +interval;
        
        NSDate *nd = [NSDate dateWithTimeIntervalSince1970:creatTime];
        
        CLog(@"返回的日志时间 %@", nd);
        
        //日志时间
        NSString *createDateStr = [[PublicMethodEngine sharedPublicMethodEngine] NSDateToNSTring:nd];
        int create_year = [[createDateStr substringWithRange: NSMakeRange(0, 4)] intValue];
        int create_month=[[createDateStr substringWithRange: NSMakeRange(5, 2)] intValue];
        int create_day=[[createDateStr substringWithRange: NSMakeRange(8, 2)] intValue];
        
        
        
        NSString *dayString;
        
        if (create_day < 10) {
            dayString = [NSString stringWithFormat:@"0%d",create_day];
            
        }
        else{
            
            dayString = [NSString stringWithFormat:@"%d",create_day];
            
        }
        
        
        NSString *monthString = [NSString stringWithFormat:@"%d月",create_month];
        
        dayLabel.text = dayString;
        monthLabel.text = monthString;
        
        
        //当前时间

        NSDate *date=[NSDate dateWithTimeIntervalSinceNow:interval];
              
        NSString *curDateStr = [[PublicMethodEngine sharedPublicMethodEngine] NSDateToNSTring:date];
        int cur_year = [[curDateStr substringWithRange: NSMakeRange(0, 4)] intValue];
        int cur_month=[[curDateStr substringWithRange: NSMakeRange(5, 2)] intValue];
        int cur_day=[[curDateStr substringWithRange: NSMakeRange(8, 2)] intValue];
        
        
        if (cur_year == create_year && cur_month == create_month && cur_day == create_day) {
            dayString = @"今天";
            monthString = @"";
            dayLabel.text=dayString;
            monthLabel.text = monthString;
            [dayLabel setFrame:CGRectMake(7, 62, 50, 26)];
            
        }
        if (cur_year == create_year && cur_month == create_month && cur_day == create_day+1) {
            dayString = @"昨天";
            monthString = @"";
            dayLabel.text=dayString;
            [dayLabel setFrame:CGRectMake(7, 62, 50, 26)];
            monthLabel.text = monthString;
        }
        
    }
    
    likeNumLabel.text = [NSString stringWithFormat:@" %d",0 ];
    commentNumLabel.text = [NSString stringWithFormat:@" %d",0 ];
    
    
    
    
    
    if([diaryDict.allKeys containsObject:@"fileData"]){ // 有图片
        
        
        /*** 显示图片 begin ***/
        float hight = 0;
        
        
        
        
        //单张照片显示
        
        if ([diaryDict.allKeys containsObject:@"fileData"]) {
            
            
            NSString *imageUrlKey = [NSString stringWithFormat:@"%@",[dict objectForKey:@"time"]]  ;
            NSData *imageData =   [[SDDataCache sharedDataCache:kImageCache_Locale_Record] dataFromKey:imageUrlKey];
            
            if (imageData) {
                imageView1.image = [UIImage imageWithData:imageData];
            }
            else{
                
                imageView1.image = [UIImage imageNamed:@"bg_imageView.png"];
                
            }
            
            imageView1.hidden = NO;
            
            
            [imageView1 setFrame:CGRectMake(6, imageView1.frame.origin.y, imageView1.frame.size.width, 200)];
            [imageView1 setContentMode:UIViewContentModeScaleAspectFill];
            [imageView1 setClipsToBounds:YES];
            
            
            hight += (200+5);
            
            imageView1.userInteractionEnabled = YES;
            
            
            //放大全屏
            
            if (pictureList == nil) {
                pictureList = [[NSArray alloc]initWithObjects:imageUrlKey, nil];
            }
            
//            fullScreenButton1.hidden = NO;
//            [fullScreenButton1 removeTarget:self action:@selector(toPhotoBook:) forControlEvents:UIControlEventTouchUpInside];
//            [fullScreenButton1 addTarget:self action:@selector(toLocalFullSize:) forControlEvents:UIControlEventTouchUpInside];
//            [fullScreenButton1 setFrame:CGRectMake(imageView1.frame.origin.x, imageView1.frame.origin.y, imageView1.frame.size.width, imageView1.frame.size.height)];
            
            
            UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(imageView1.frame.origin.x, imageView1.frame.origin.y, imageView1.frame.size.width, imageView1.frame.size.height) ];
           
            button.tag = 321;
            button.backgroundColor = [UIColor clearColor];
            [button addTarget:self action:@selector(toLocalFullSize:) forControlEvents:UIControlEventTouchUpInside];
            [conttentView addSubview:button];
            [button release];
            
            
        }
        
        
        
        
        
        /***  显示文字  begin ***/
        
        
        conttentLabel.numberOfLines = 0;
        conttentLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [conttentLabel setFont:[UIFont systemFontOfSize:14]];
        
        NSString *content = [diaryDict objectForKey:@"diaryContent"];
        
        content = [self changeStringFommat:content];
        
        if (![content isMemberOfClass:[NSNull class]]) {
            
            if (content.length>50) {
                content = [content substringToIndex:50];
                
                content = [NSString stringWithFormat:@"%@......",content];
            }
            
            
        }
        
        
        
        UIFont *font = [UIFont systemFontOfSize:15];
        CGSize size = CGSizeMake(225,2000);
        CGSize labelsize = [content sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeCharacterWrap]; 
        
        [conttentLabel setFrame:CGRectMake(6, 35+hight, labelsize.width, labelsize.height+10)];
        conttentLabel.text = content;
        conttentLabel.backgroundColor = [UIColor clearColor];
        
        
        
        [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, hight+conttentLabel.frame.size.height +40)];
        
        [self conttentViewShadow];
        
        //地理位置
        
        if(![[diaryDict objectForKey:@"local"] isMemberOfClass:[NSNull class]])
        { 
            
            adressLabel.text=[diaryDict objectForKey:@"local"];
            adressLabel.backgroundColor = [UIColor clearColor];
            
            
        }
        
        
        
    }
    
    
    else{   /***  无图 纯文字  ***/
        
        
        
        conttentLabel.numberOfLines = 0;
        conttentLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        conttentLabel.backgroundColor = [UIColor clearColor];
        [conttentLabel setFont:[UIFont systemFontOfSize:14]];
        
        
        NSString *content = [diaryDict objectForKey:@"diaryContent"];
        content = [self changeStringFommat:content];
        
        if (![content isMemberOfClass:[NSNull class]]) {
            
            if (content.length>50) {
                content = [content substringToIndex:50];
                
                content = [NSString stringWithFormat:@"%@......",content];
                
            }
            
            
        }
        
        UIFont *font = [UIFont systemFontOfSize:15];
        CGSize size = CGSizeMake(225,2000);
        CGSize labelsize = [content sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeCharacterWrap];                
        
        [conttentLabel setFrame:CGRectMake(6, 25, labelsize.width, labelsize.height)];
        conttentLabel.text = content;
        conttentLabel.backgroundColor = [UIColor clearColor];
        
        
        [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, conttentLabel.frame.size.height +10 +40)];
        [self conttentViewShadow];
        
        
        //地理位置
        
        if(![[diaryDict objectForKey:@"local"] isMemberOfClass:[NSNull class]])
        { 
            
            adressLabel.text=[diaryDict objectForKey:@"local"];
            
        }
        
        
    }
    
    
    
    
    if (conttentView.frame.size.height <100) {
        if ([[diaryDict objectForKey:@"local"] isMemberOfClass:[NSNull class]] ) {
            
            [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, 80)]; 
            [self conttentViewShadow];
            
        }
        else if([[diaryDict objectForKey:@"local"] isEqualToString:@""]){
            [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, 80)]; 
            [self conttentViewShadow];
            
        }
        else{
            
            [conttentView setFrame:CGRectMake(conttentView.frame.origin.x, conttentView.frame.origin.y, conttentView.frame.size.width, 100)];
            [self conttentViewShadow];
            
        }
        
    }
    
    
    CGRect cellFrame = [self frame];
    cellFrame.origin = CGPointMake(0, 0);
    
    cellFrame.size.height = conttentView.frame.size.height + 20;
    [self setFrame:cellFrame];
  
    
}


- (void)loadTimelineIconButtonWithLocal{
    
    
    
    //名字
    if ([[NSUserDefaults standardUserDefaults] valueForKey:@"userName"]) {
        
        nameLabel.text =  [[NSUserDefaults standardUserDefaults] valueForKey:@"userName"];
    }
    
    
	//头像
    
    if ([[NSUserDefaults standardUserDefaults] valueForKey:@"userAttachmentId"]) {
        
        
       // NSString *string=[NSString stringWithFormat:@"%@%@/%@/100x100",BASEURL,@"/commons/attachment/download",[[NSUserDefaults standardUserDefaults] valueForKey:@"userAttachmentId"]];
        
         NSString *string=[NSString stringWithFormat:@"%@/%@/%@/100x100",UCENTERBASEURL,@"gravatar",[[NSUserDefaults standardUserDefaults] valueForKey:@"userAttachmentId"]];
        NSURL *url = [NSURL URLWithString:string];	
        CLog(@"icon url %@", string);
        
        //[iconImageView setImageWithURL:url imageType:kImageCache_Content_Icon]; 
        //[self setImageViewWith:iconImageView url:url imageType:kImageCache_Content_Icon];
        [iconImageView setImageWithURL:url refreshCache:NO placeholderImage:[UIImage imageNamed:@"geren_set_iphone.png"] imageType:kImageCache_Content_Icon];
        
        
        if([[NSUserDefaults standardUserDefaults] valueForKey:@"userId"]){
            iconButton.tag = [[[NSUserDefaults standardUserDefaults] valueForKey:@"userId"] intValue];
            [iconButton addTarget:self action:@selector(toUserView:) forControlEvents:UIControlEventTouchUpInside];   
        }
        
	}
    
    
    
    
    
}


#pragma mark 字符串过滤

-(NSString *)changeStringFommat:(NSString *)str{
    
    PublicMethodEngine *methodEngine = [PublicMethodEngine sharedPublicMethodEngine];   
    
    return  [methodEngine changeStringFommat:str];
    
    
    
}


- (IBAction)toUserView:(id)sender{
    
    
    UIButton *button = (UIButton *)sender;
    if (self.delegate!=nil) {
        [self.delegate toUserView:button];
    }
    
    
}

- (void)toTimelineSetting{
    
    if (self.delegate != nil) {
        [self.delegate toTimelineSetting];
    }
    
}

- (IBAction)toBabyTimelineView:(id)sender{   //跳到宝宝主页
    UIButton *button = (UIButton *)sender;
    if (self.delegate!=nil) {
       
        [self.delegate toBabyTimelineView:button];
    }
    
    
}




#pragma mark 滑动相册
- (IBAction)toPhotoBook:(NSArray *)images{
    
    if (self.delegate != nil) {
        [self.delegate toPhotoBook:pictureList];
    }
    
}

- (void)toLocalFullSize:(NSArray *)images{
    
    if (self.delegate != nil) {
        [self.delegate toLocalFullSize:pictureList];
    }

    
    
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
